$(document).ready(function () {
    $("#change-password-btn").on("click", function() {
        if (changePasswordValidate()) {
            var data = { OldPassWord: $("#old-password").val(), NewPassWord1: $("#new-password").val(), NewPassWord2: $("#new-repeat-password").val()};
            var url = "../Handle/LogHandlerService.ashx?method=Modify_One_Family_PWD";
            $.ajax({
                type: "POST",
                data: data,
                url: url,
                dataType: "json",
                success: function (data) {
                	//console.log(data);
                    if (-1 == data.MessageType) {
                        // alert(data.MessageContent);
                        $("#dialog-modal-label").text(data.MessageContent);
                        $("#DialogModal").modal("show");
                    } else if (1 == data.MessageType) {
                        // alert(data.MessageContent);
                        // $("#dialog-modal-label").text(data.MessageContent);
                        // $("#DialogModal").modal("show");
                        logOut();
                    }
                }
            });
        }
    });
});

function changePasswordValidate() {
    return $("#change-password-form").validate({
        errorClass: "warning",
        rules: {
            oldPassword: {
                required: true,
            },
            newPassword: {
                required: true,
                minlength: 6
            },
            newRepeatPassword: {
                required: true,
                minlength: 6,
                equalTo:"#new-password"
            },
        },
        messages: {
            oldPassword: {
                required: "请输入旧密码",
            },
            newPassword: {
                required: "请输入密码",
                minlength: "密码长度不能小于 6 个字母"
            },
            newRepeatPassword: {
                required: "请输入密码",
                minlength: "密码长度不能小于 6 个字母",
                equalTo:"两次密码输入不一致"
            },
        }
    }).form();
}